home *** CD-ROM | disk | FTP | other *** search
- Path: hal.COM!spike
- From: spike@hal.com (Spike White)
- Newsgroups: comp.lang.c++
- Subject: Using typedefs in templates (not a FAQ)
- Date: 5 Mar 1996 22:58:46 GMT
- Organization: HAL Computer Systems, Inc.
- Message-ID: <4higv6$7ih@news.hal.com>
- NNTP-Posting-Host: zarathustra.hal.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- I want to typedef a new type based on the types of the formal template
- parameter list. Is that possible?
-
- Something like:
-
- template <class KEY, class NODEDATA>
- class Tree {
- public:
- typedef int (*pfid)(NODEDATA);
- typedef int (*pfi2c)(const KEY, const NODEDATA);
- ...
- pfi2c pfi_compare; // my compare function
- ...
- int trav(pfid); // perform the function on each node
- ...
- }
-
- Obviously, I could "uglify" my header file and C file by replacing the
- typedefs w/ the literal expansion, but I'd rather not do that. And I
- can't figure out a macro that would work.
-
- I've also considered passing these new types when instantiating, as
- the 3rd and 4th formal parameters. How would that be done? Would it be
- something like:
-
- template <class KEY, class NODEDATA, class int (*pfid)(NODEDATA), ... >
- {
- ...
- }
-
- --
- Spike White | spike@hal.com | Biker Nerds
- HaL Software Systems | '87 BMW K75S, DoD #1347 | From HaL
- Austin, TX | http://www.halsoft.com/users/spike/index.html
- Disclaimer: HaL, want me to speak for you? No, Dave...
-